import request from '@/utils/request'

const pageByCond = (currentPage, pageSize, data) => {
  return request({
    url: `/products/list?pageNum=${currentPage}&pageSize=${pageSize}`,
    method: 'post',
    data,
  })
}

const listByName = (name) => {
  return request({
    url: `/products/listByName?name=${name}`,
    method: 'get',
  })
}

const getById = (id) => {
  let product = {
    id: '',
  }
  product.id = id
  return get(product)
}

const get = (data) => {
  return request({
    url: `/products/get`,
    method: 'post',
    data,
  })
}

const remove = (id) => {
  return request({
    url: `/products/remove/${id}`,
    method: 'delete',
  })
}

const updateById = (data) => {
  return request({
    url: `/products/update`,
    method: 'put',
    data,
  })
}
const create = (data) => {
  return request({
    url: `/products/create`,
    method: 'post',
    data,
  })
}
export default {
  getById,
  updateById,
  remove,
  pageByCond,
  create,
  listByName,
}
